package com.qf.controller;

import com.qf.pojo.Order;
import com.qf.pojo.UserInfo;
import com.qf.pojo.resp.BaseResult;
import com.qf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Date;


@RestController
@CrossOrigin
public class OrderController {

    @Autowired
    OrderService orderService;
    @RequestMapping("/addOrder")
    public BaseResult add(@RequestBody Order order ,HttpSession session){
        session.setAttribute("user",new UserInfo(1,"zhangsan"));
        UserInfo user = (UserInfo) session.getAttribute("user");
        Integer uid = user.getId();
        order.setUid(uid);
        order.setCreatTime(new Date());
        BaseResult order1 = orderService.addOrder(order);
        return order1;
    }
}
